#ifndef _MAP_STATE_H_
#define _MAP_STATE_H_

#include "gameflow/ui_state.h"

class MapState : public gameflow::UIState
{
public:

	MapState(	camera::FbCamera*	pCamera, const std::string& BasePanel = "", const std::string& ExecuteOnEnter = "",  const std::string& ExecuteOnLeave = "" );
	virtual	~MapState();
	static MapState*	GetMap();
	static void			Register(LuaPlus::LuaState* pState);



	virtual void		SetLevelState(int ID, int State);
	virtual int			GetLevelState(int ID);

protected:
	struct				LevelData
	{
		int					LevelID;	
		int					StateID;	
		int					PreReqA;	
		int					PreReqB;	

		std::string			Widget;	
		std::string			Panel;	
		std::string			ClosedImg;
		std::string			OpenOverImg;	
		std::string			OpenOffImg;	
		std::string			CompleteOverImg;	
		std::string			CompleteOffImg;	
		std::string			Script;
	};

	// functions to access from outside
	int					GetCurrentLevel();			// what's the current level ID?
	void				SetCurrentLevel(int ID);	// set the current Level ID	
	void				SetCurrentState(int State);	// 0 = closed. 1 = open. 2 = complete
	int					GetHighestOpen();			// highest open
	void				Refresh();					// update the UI state
	void				OpenCurrent();				// open the latest state
	void				TriggerAdvance();			


	// helper functions internally
	virtual void		Load(const std::string&	File);
	virtual void		OpenState(int ID);			// override this to provide custom UI opening animations
	virtual bool		IsStateOpen(int ID);		// check if a state is open
	virtual bool		IsLevelOpen(int ID);		// check if level prereqs are open
	virtual bool		IsLevelComplete(int ID);	// check if level prereqs are open


	void				RefreshSet(int StateID);
	ui::UIWidget*		GetWidgetFromLevel(int ID);	// given a level ID, get the right panel and Widget
	ui::UIWidget*		GetPanelFromState(int ID);	// given a state ID, get the right panel

	LevelData*			GetLevel(int ID);
	num::NamedSet<LevelData*>	m_LevelData;
	int							m_CurrentLevel;

};

#endif // MAP_STATE_H_